<!DOCTYPE html>
<html lang="ZH-cn">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>Login</title>
	<link rel="stylesheet" href="__PLUGIN__/layui/css/layui.css">
	<link rel="stylesheet" href="__ACSS__/login.css">
	<style>
		.kit-login-bg {
			background-image: url(/public/static/admin/images/a2.jpg)
		}
	</style>
</head>

<body>
	<div class="kit-login">
		<div class="kit-login-bg" style=""></div>
		<div class="kit-login-wapper">
			<h2 class="kit-login-slogan">艾莫森通用航空公司
				<br> 后台管理</h2>
			<div class="kit-login-form">
				<!-- <h4 class="kit-login-title">登录</h4> -->
				<form class="layui-form">
					<div class="kit-login-row">
						<div class="kit-login-col">
							<i class="layui-icon">&#xe612;</i>
							<span class="kit-login-input">
								<input type="text" name="username" lay-verify="required" placeholder="账号" autocomplete="off"/>
							</span>
						</div>
						<div class="kit-login-col"></div>
					</div>
					<div class="kit-login-row">
						<div class="kit-login-col">
							<i class="layui-icon">&#xe64c;</i>
							<span class="kit-login-input">
								<input type="password" name="password" lay-verify="required" placeholder="密码" autocomplete="off"/>
							</span>
						</div>
						<div class="kit-login-col"></div>
					</div>
					<div class="kit-login-row">
						<div class="kit-login-col">
							<img style="float: left; width: 110px;height: 38px;" id="verify_img" src="{:url('user/captcha_src')}" alt="验证码" onclick="refreshVerify()">
							<span style="width: 99px; float: left;">
								<input type="text" name="verify" required lay-verify="required" placeholder="验证码" autocomplete="off" class="layui-input">
							</span>
						</div>
						<div class="kit-login-col"></div>
					</div>
					<div class="kit-login-row" style="margin-bottom: 0;">
						<button class="layui-btn kit-login-btn" lay-submit="submit" lay-filter="formSub">登录</button>
					</div>
				</form>
			</div>
		</div>
	</div>

<script src="__AJS__/polyfill.min.js"></script>
<script src="__PLUGIN__/layui/layui.js"></script>
<script>
	layui.use(['layer', 'form', 'jquery'], function () {
		var layer = layui.layer,
			form = layui.form,
			$ = layui.jquery;

		// 自定义验证规则
		form.verify({
			username: function(value, item){ //value：表单的值、item：表单的DOM对象
				if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
					return '用户名不能有特殊字符';
				}
				if(/(^\_)|(\__)|(\_+$)/.test(value)){
					return '用户名首尾不能出现下划线\'_\'';
				}
				if(/^\d+\d+\d$/.test(value)){
					return '用户名不能全为数字';
				}
			},
			password: [/(.+){6,12}$/, '密码必须6到12位'],
			verify: [/(.+){4,4}$/, '验证码必须4位'],
		});

		// 提交表单
		form.on('submit(formSub)', function(data){
			var url  = "{:url('user/check')}";

			/*if (data.field.password != data.field.repassword) {
				return layer.msg('两次密码输入不一致', {icon: 5});
			}*/
			$.post(url, data.field, function(result) {
				if (result.status == 0) {
					layer.msg(result.message);
					setTimeout(function() {
						window.location.href = "/admin/"; // 跳转
						// document.location.reload(); // 重载页面
					}, 1000);
				} else {
					layer.msg(result.message);
				}
			},"JSON");

			console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
			return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});
	});

	function refreshVerify() {
		var ts  = Date.parse(new Date())/1000;
		var img = document.getElementById('verify_img');
		// img.src = "/captcha?id="+ts;
		img.src = "{:url('user/captcha_src')}?id="+ts;
	}
</script>
</body>

</html>